package zhai.git.test;

/**
 * @author Created by 翟凤玺
 * @package zhai.git.test
 * @project-name 项目名称
 * @description //TODO 请对该类编写一个描述
 * @create-datetime 2021/4/26 13:37
 */
class Race implements Runnable {

    private static String winer;


    public void run() {
        for (int i = 0; i <= 500; i++) {
            if ("兔子".equals(Thread.currentThread().getName()) && i%10==0) {
                System.out.println("兔子第"+ i + "步　休息1毫秒");
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (winer != null) {
                break;
            }
            System.out.println(Thread.currentThread().getName() + " -> 跑了" + i + "步");
        }
        winer = Thread.currentThread().getName();
        System.out.println(winer);
    }

    public static void main(String[] args) {
        Runnable race = new Race();
        new Thread(race, "兔子").start();
        new Thread(race, "乌龟").start();
    }

}